package com.sina.shop.api;

import com.sina.shop.domain.carousel.Carousel;
import com.sina.shop.service.carousel.CarouselService;
import com.sina.shop.web.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * 段浩杰   2018-02-07-18:10
 */
@RestController
@RequestMapping("/carousel")
public class CarouselController extends BaseController {

    @Autowired
    @Qualifier("carouselService")
    private CarouselService carouselService;

    @Autowired
    private DiscoveryClient discoveryClient;

    @RequestMapping(value = "/getCarousel", method = RequestMethod.GET)
    public List<Carousel> getCarousel() {
        ServiceInstance instance = discoveryClient.getLocalServiceInstance();
        LOG.info("/getCarousel, method: get, host:" + instance.getHost() + ", serviceId:" + instance.getServiceId() + ",time: " + LocalDateTime.now());
        return carouselService.getCarousel();
    }
}
